--[[
	ALL SPECS
]]
function ccR_DeathKnight_RisenAlly_Exists()
	local name = ccRS.DeathKnight_RisenAlly
	local iDescriptor = ccRS.DeathKnight_RisenAllyDescriptor
	if name == nil then name = "Risen Ally" end
	if iDescriptor == nil then iDescriptor = "0x48" end
	for i = 0, # ccrObjectListTable do
		local TableObject = ccrObjectListTable[i]
		if TableObject ~= nil
		and TableObject:Exists()
		and TableObject:GetName() == name
		and TableObject:GetInt64Descriptor(iDescriptor) == Player:GetGUID()
		then
			-- Found it
			return true
		end
	end
	-- Not found
	return false
end
function ccR_DeathKnight_RequiresBloodBoil()
	if ccrTargetIsWithinDistance(10)
	and (vLastBloodBoilCheck == nil or (GetTime()-vLastBloodBoilCheck > 0.5))
	then
		objTable = Target:GetNearbyEnemies(10)
		for i = 1, # objTable do
			if objTable[i] ~= nil
			and not objTable[i]:IsDead()
			and objTable[i]:GetCreatureInfo() ~= "Totem"
			and objTable[i]:GetCreatureInfo() ~= "Critter"
			and objTable[i]:GetCreatureInfo() ~= "Wild Pet"
			and (objTable[i]:GetAura("Blood Plague") == nil or objTable[i]:GetAura("Frost Fever") == nil)
			then
				vLastBloodBoilCheck = GetTime()
				return true
			end;
		end
		vLastBloodBoilCheck = GetTime()
		return false
	else
		vLastBloodBoilCheck = GetTime()
		return false
	end;
end	

function ccR_DeathKnight_DeathStrike()
	local vDeathStrikeHP
	local vDeathStrikeOnProc
	local vDeathStrikeOnProcHP
	local vUseDeathStrike
	vUseDeathStrike = ccRS.DeathKnight_UseDeathStrike
	vDeathStrikeHP = ccRS.DeathKnight_DeathStrikeHP
	vDeathStrikeOnProc = ccRS.DeathKnight_DeathStrikeOnProc
	vDeathStrikeOnProcHP = ccRS.DeathKnight_DeathStrikeOnProcHP

	if vUseDeathStrike then
		-- Use Death Strike if below a certain % of health
		if ccrSpellCanAttack(DEATH_STRIKE)
		and ccrPlayerHealth() <= vDeathStrikeHP
		and ccrSpellCanAttack(DEATH_STRIKE)
		then
			ccrCastAttack(DEATH_STRIKE)
			return
		end
		return
	end

	if vDeathStrikeOnProc then
		if ccrPlayerHealth() <= vDeathStrikeOnProcHP
		and ccrPlayerHasBuff(DARK_SUCCOR)
		and ccrSpellCanAttack(DEATH_STRIKE)
		then
			ccrCastAttack(DEATH_STRIKE)
			return
		end
		return
	end

	return
end

function ccR_DeathKnight_RaiseDead()
	local vRaiseDead = nil
	local vRaiseDeadOnBuffs = nil
	vRaiseDead = ccRS.DeathKnight_UseRaiseDead 
	vRaiseDeadOnBuffs = ccRS.DeathKnight_UseRaiseDeadOnBuffs

	if ccrSpec() == 3 then
		if vRaiseDead
		and ccrSpellIsReady(RAISE_DEAD)
		and ccrPlayerIsInCombat()
		and UnitExists("pet") == nil
		then
			ccrCast(RAISE_DEAD)
			return
		end
	else
		if vRaiseDead
		or (vRaiseDeadOnBuffs and (ccrPlayerHasBuff(PILLAR_OF_FROST) or ccrPlayerHasBuff(HEROISM) or ccrPlayerHasBuff(BLOODLUST) or ccrPlayerHasBuff(TIME_WARP)))
		and ccrSpellIsReady(RAISE_DEAD)
		and ccrPlayerIsInCombat()
		then
			ccrCast(RAISE_DEAD)
			return
		end
	end
	return
end

--[[
	FROST
]]
function ccR_DeathKnight_PillarOfFrost()
	if ccRS.DeathKnight_2_UsePillarOfFrost
	and ccrPlayerHasSpell(PILLAR_OF_FROST)
	and ccrSpellIsReady(PILLAR_OF_FROST)
	and ccrPlayerIsInCombat()
	and ccrTargetIsWithinMeleeRange()
	then
		ccrCast(PILLAR_OF_FROST)
		return
	end
	return
end

--[[
	UNHOLY
]]
function ccR_DeathKnight_Summon_Gargoyle()
	local vUseGargoyle = ccRS.DeathKnight_3_UseSummonGargoyle
	local vUseGargoyleOnBuffs = ccRS.DeathKnight_3_UseSummonGargoyleOnBuffs
	if ccrPlayerHasSpell(SUMMON_GARGOYLE)
	and ccrSpellIsReady(SUMMON_GARGOYLE)
	and (vUseGargoyle or (vUseGargoyleOnBuffs and ccrPlayerHasBuff(UNHOLY_FRENZY)))
	then
		ccrCast(SUMMON_GARGOYLE)
		return
	end
	return
end

function ccR_DeathKnight_Unholy_Frenzy()
	local vUseUnholyFrenzy = ccRS.DeathKnight_3_UseUnholyFrenzy
	if ccrPlayerHasSpell(UNHOLY_FRENZY)
	and vUseUnholyFrenzy
	and ccrSpellIsReady(UNHOLY_FRENZY)
	then
		ccrCast(UNHOLY_FRENZY)
		return
	end
	return
end